﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Naruto.Subscribe;
using Naruto.TaskManagement.Entitys.Const;
using Naruto.TaskManagement.Entitys.DTO;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Naruto.TaskManagement.Application.Subscribe
{
    public class ChatMessageSubscribe : ISubscribe
    {
        private readonly IServiceProvider serviceProvider;


        private readonly ILogger logger;

        public ChatMessageSubscribe(ILogger<ChatMessageSubscribe> _logger, IServiceProvider _serviceProvider)
        {
            logger = _logger;
            serviceProvider = _serviceProvider;
        }
        [Subscribe(name: ConstObject.UpdateSessionStateSubscribeKey)]
        /// <summary>
        /// 更新会话状态
        /// </summary>
        /// <returns></returns>
        public async Task UpdateSessionState(UpdateChatSessionStateDTO info)
        {
            using var scopeServicePrivider = serviceProvider.CreateScope();
            var chatSessionApp = scopeServicePrivider.ServiceProvider.GetRequiredService<ChatSessionStateApps>();
            await chatSessionApp.Update(info);
        }
    }
}
